//
//  YTTNavigationController.m
//  跑圈儿
//
//  Created by 唐康 on 16/4/19.
//  Copyright © 2016年 唐康. All rights reserved.
//

#import "YTTNavigationController.h"

@interface YTTNavigationController ()

@end

@implementation YTTNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationBar.tintColor = [UIColor whiteColor];
    self.interactivePopGestureRecognizer.delegate = nil;
    self.navigationBar.barTintColor = YTTRGBColor(71, 153, 221);
    self.navigationBar.barStyle = UIBarStyleBlack;
}


//可以在这个方法中拦截所有push进来的控制器
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.childViewControllers.count > 0) {
        
        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
               [button setImage:[UIImage imageNamed:@"back"] forState:(UIControlStateNormal)];
        [button setImage:[UIImage imageNamed:@"back_click"] forState:(UIControlStateHighlighted)];
        // button.backgroundColor = [UIColor blueColor];
        button.size = CGSizeMake(40, 30);
        //按钮内容 靠做
        button.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [button setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
        [button setTitleColor:[UIColor redColor] forState:(UIControlStateHighlighted)];
        [button addTarget:self action:@selector(back) forControlEvents:(UIControlEventTouchUpInside)];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
        
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];

}

-(void)back{
    [self popViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
